package com.sooncode.project.focusservice._.infrastructure;

import com.sooncode.project.core.model.DomainRepository;
import com.sooncode.project.core.model.EventStore;
import com.sooncode.project.core.model.IDomainRepository;
import com.sooncode.project.core.model.IEventStore;
import com.sooncode.project.focusservice._.infrastructure.file.IStoreFile;
import com.sooncode.project.focusservice._.infrastructure.file.StoreFile;
import com.sooncode.project.sooncodeutils.infrastructrue.dao.MongoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

@Component
@RefreshScope
public class RepositoryFactory {
    IEventStore eventStore;
    @Autowired
    StoreFile storeFile;
    @Autowired
    public RepositoryFactory(MongoConfig config){
        MongoRepository repository=MongoRepository.Init(config.getMongoConnection(),config.getMongoPort(),config.getMongoDatabase(),config.getMongoUsername(),config.getMongoPassword());
        this.eventStore=new EventStore(repository.getRepository());
    }
    public IDomainRepository getRepository(){
        return new DomainRepository(eventStore);
    }
    public IStoreFile getStoreFile(){return storeFile;}
}
